﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_DrawingDetails : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            long ID = ShoveEL._Convert.StrToLong(this.Request["id"], -1);

            if ((_User.Competences.IsOwnedCompetences(Competences.BuildCompetencesList(Competences.Administrator))) && (ID >= 0))
            {
                tbID.Text = ID.ToString();
            }
            else
            {
                tbID.Text = _User.ID.ToString();
            }

            DataBindDataGrid();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestLoginPage = "BalanceCenter/DrawingDetails.aspx";

        base.OnInit(e);
    }

    #endregion

    private void DataBindDataGrid()
    {
        DataTable dt = DAL.Views.V_UserDistills.Select("", "ID = " + tbID.Text, "[DateTime] desc");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        g.DataSource = dt;
        g.DataBind();
    }

    protected void g_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            double Money = ShoveEL._Convert.StrToDouble(e.Item.Cells[2].Text, 0);
            e.Item.Cells[2].Text = Money.ToString("N");

            //0 表示处理中 1 表示已提交 2 表示处理成功
            int Result = ShoveEL._Convert.StrToInt(e.Item.Cells[4].Text.ToString(), 0);

            if (Result == 2)
            {
                e.Item.Cells[4].Text = "已成功";
            }
            else if (Result == 1)
            {
                e.Item.Cells[4].Text = "处理中";
            }
            else if (Result == -1)
            {
                e.Item.Cells[4].Text = "拒绝提款";
            }
            else
            {
                e.Item.Cells[4].Text = "未处理";
            }

            int num = (gPager.PageIndex * gPager.PageSize) + e.Item.ItemIndex + 1;
            e.Item.Cells[0].Text = num.ToString();
        }
    }

    protected void gPager_SortBefore(object source, DataGridSortCommandEventArgs e)
    {
        DataBindDataGrid();
    }

    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        DataBindDataGrid();
    }
}